/*
 * Copyright 2011 Katsunori Koyanagi
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package sweezy.swf.action
{
	import sweezy.swf.action.code.ActionAdd;
	import sweezy.swf.action.code.ActionAdd2;
	import sweezy.swf.action.code.ActionAnd;
	import sweezy.swf.action.code.ActionAsciiToChar;
	import sweezy.swf.action.code.ActionBitAnd;
	import sweezy.swf.action.code.ActionBitLShift;
	import sweezy.swf.action.code.ActionBitOr;
	import sweezy.swf.action.code.ActionBitRShift;
	import sweezy.swf.action.code.ActionBitURShift;
	import sweezy.swf.action.code.ActionBitXor;
	import sweezy.swf.action.code.ActionCall;
	import sweezy.swf.action.code.ActionCallFunction;
	import sweezy.swf.action.code.ActionCallMethod;
	import sweezy.swf.action.code.ActionCastOp;
	import sweezy.swf.action.code.ActionCharToAscii;
	import sweezy.swf.action.code.ActionCloneSprite;
	import sweezy.swf.action.code.ActionConstantPool;
	import sweezy.swf.action.code.ActionDecrement;
	import sweezy.swf.action.code.ActionDefineFunction;
	import sweezy.swf.action.code.ActionDefineFunction2;
	import sweezy.swf.action.code.ActionDefineLocal;
	import sweezy.swf.action.code.ActionDefineLocal2;
	import sweezy.swf.action.code.ActionDelete;
	import sweezy.swf.action.code.ActionDelete2;
	import sweezy.swf.action.code.ActionDivide;
	import sweezy.swf.action.code.ActionEndDrag;
	import sweezy.swf.action.code.ActionEnumerate;
	import sweezy.swf.action.code.ActionEnumerate2;
	import sweezy.swf.action.code.ActionEquals;
	import sweezy.swf.action.code.ActionEquals2;
	import sweezy.swf.action.code.ActionExtends;
	import sweezy.swf.action.code.ActionGetMember;
	import sweezy.swf.action.code.ActionGetProperty;
	import sweezy.swf.action.code.ActionGetTime;
	import sweezy.swf.action.code.ActionGetURL;
	import sweezy.swf.action.code.ActionGetURL2;
	import sweezy.swf.action.code.ActionGetVariable;
	import sweezy.swf.action.code.ActionGoToLabel;
	import sweezy.swf.action.code.ActionGotoFrame;
	import sweezy.swf.action.code.ActionGotoFrame2;
	import sweezy.swf.action.code.ActionGreater;
	import sweezy.swf.action.code.ActionIf;
	import sweezy.swf.action.code.ActionImplementsOp;
	import sweezy.swf.action.code.ActionIncrement;
	import sweezy.swf.action.code.ActionInitArray;
	import sweezy.swf.action.code.ActionInitObject;
	import sweezy.swf.action.code.ActionJump;
	import sweezy.swf.action.code.ActionLess;
	import sweezy.swf.action.code.ActionLess2;
	import sweezy.swf.action.code.ActionMBAsciiToChar;
	import sweezy.swf.action.code.ActionMBCharToAscii;
	import sweezy.swf.action.code.ActionMBStringExtract;
	import sweezy.swf.action.code.ActionMBStringLength;
	import sweezy.swf.action.code.ActionModulo;
	import sweezy.swf.action.code.ActionMultiply;
	import sweezy.swf.action.code.ActionNewMethod;
	import sweezy.swf.action.code.ActionNewObject;
	import sweezy.swf.action.code.ActionNextFrame;
	import sweezy.swf.action.code.ActionNot;
	import sweezy.swf.action.code.ActionOr;
	import sweezy.swf.action.code.ActionPlay;
	import sweezy.swf.action.code.ActionPop;
	import sweezy.swf.action.code.ActionPreviousFrame;
	import sweezy.swf.action.code.ActionPush;
	import sweezy.swf.action.code.ActionPushDuplicate;
	import sweezy.swf.action.code.ActionRandomNumber;
	import sweezy.swf.action.code.ActionRemoveSprite;
	import sweezy.swf.action.code.ActionReturn;
	import sweezy.swf.action.code.ActionSetMember;
	import sweezy.swf.action.code.ActionSetProperty;
	import sweezy.swf.action.code.ActionSetTarget;
	import sweezy.swf.action.code.ActionSetTarget2;
	import sweezy.swf.action.code.ActionSetVariable;
	import sweezy.swf.action.code.ActionStackSwap;
	import sweezy.swf.action.code.ActionStartDrag;
	import sweezy.swf.action.code.ActionStop;
	import sweezy.swf.action.code.ActionStopSounds;
	import sweezy.swf.action.code.ActionStoreRegister;
	import sweezy.swf.action.code.ActionStrictEquals;
	import sweezy.swf.action.code.ActionStringAdd;
	import sweezy.swf.action.code.ActionStringEquals;
	import sweezy.swf.action.code.ActionStringExtract;
	import sweezy.swf.action.code.ActionStringGreater;
	import sweezy.swf.action.code.ActionStringLength;
	import sweezy.swf.action.code.ActionStringLess;
	import sweezy.swf.action.code.ActionSubtract;
	import sweezy.swf.action.code.ActionTargetPath;
	import sweezy.swf.action.code.ActionThrow;
	import sweezy.swf.action.code.ActionToInteger;
	import sweezy.swf.action.code.ActionToNumber;
	import sweezy.swf.action.code.ActionToString;
	import sweezy.swf.action.code.ActionToggleQuality;
	import sweezy.swf.action.code.ActionTrace;
	import sweezy.swf.action.code.ActionTry;
	import sweezy.swf.action.code.ActionTypeOf;
	import sweezy.swf.action.code.ActionWaitForFrame;
	import sweezy.swf.action.code.ActionWaitForFrame2;
	import sweezy.swf.action.code.ActionWith;

	public class ActionInfo
	{

		public static const ACTION_ADD:uint = 0x0a;

		public static const ACTION_ADD_2:uint = 0x47;

		public static const ACTION_AND:uint = 0x10;

		public static const ACTION_ASCII_TO_CHAR:uint = 0x33;

		public static const ACTION_BIT_AND:uint = 0x60;

		public static const ACTION_BIT_L_SHIFT:uint = 0x63;

		public static const ACTION_BIT_OR:uint = 0x61;

		public static const ACTION_BIT_R_SHIFT:uint = 0x64;

		public static const ACTION_BIT_UR_SHIFT:uint = 0x65;

		public static const ACTION_BIT_XOR:uint = 0x62;

		public static const ACTION_CALL:uint = 0x9e;

		public static const ACTION_CALL_FUNCTION:uint = 0x3d;

		public static const ACTION_CALL_METHOD:uint = 0x52;

		public static const ACTION_CAST_OP:uint = 0x2b;

		public static const ACTION_CHAR_TO_ASCII:uint = 0x32;

		public static const ACTION_CLONE_SPRITE:uint = 0x24;

		public static const ACTION_CONSTANT_POOL:uint = 0x88;

		public static const ACTION_DECREMENT:uint = 0x51;

		public static const ACTION_DEFINE_FUNCTION:uint = 0x9b;

		public static const ACTION_DEFINE_FUNCTION_2:uint = 0x8e;

		public static const ACTION_DEFINE_LOCAL:uint = 0x3c;

		public static const ACTION_DEFINE_LOCAL_2:uint = 0x41;

		public static const ACTION_DELETE:uint = 0x3a;

		public static const ACTION_DELETE_2:uint = 0x3b;

		public static const ACTION_DIVIDE:uint = 0x0d;

		public static const ACTION_END_DRAG:uint = 0x28;

		public static const ACTION_ENUMERATE:uint = 0x46;

		public static const ACTION_ENUMERATE_2:uint = 0x55;

		public static const ACTION_EQUALS:uint = 0x0e;

		public static const ACTION_EQUALS_2:uint = 0x49;

		public static const ACTION_EXTENDS:uint = 0x69;

		public static const ACTION_GET_MEMBER:uint = 0x4e;

		public static const ACTION_GET_PROPERTY:uint = 0x22;

		public static const ACTION_GET_TIME:uint = 0x34;

		public static const ACTION_GET_URL:uint = 0x83;

		public static const ACTION_GET_URL_2:uint = 0x9a;

		public static const ACTION_GET_VARIABLE:uint = 0x1c;

		public static const ACTION_GOTO_FRAME:uint = 0x81;

		public static const ACTION_GOTO_FRAME_2:uint = 0x9f;

		public static const ACTION_GO_TO_LABEL:uint = 0x8c;

		public static const ACTION_GREATER:uint = 0x67;

		public static const ACTION_IF:uint = 0x9d;

		public static const ACTION_IMPLEMENTS_OP:uint = 0x2c;

		public static const ACTION_INCREMENT:uint = 0x50;

		public static const ACTION_INIT_ARRAY:uint = 0x42;

		public static const ACTION_INIT_OBJECT:uint = 0x43;

		public static const ACTION_JUMP:uint = 0x99;

		public static const ACTION_LESS:uint = 0x0f;

		public static const ACTION_LESS_2:uint = 0x48;

		public static const ACTION_MBASCII_TO_CHAR:uint = 0x37;

		public static const ACTION_MBCHAR_TO_ASCII:uint = 0x36;

		public static const ACTION_MBSTRING_EXTRACT:uint = 0x35;

		public static const ACTION_MBSTRING_LENGTH:uint = 0x31;

		public static const ACTION_MODULO:uint = 0x3f;

		public static const ACTION_MULTIPLY:uint = 0x0c;

		public static const ACTION_NEW_METHOD:uint = 0x53;

		public static const ACTION_NEW_OBJECT:uint = 0x40;

		public static const ACTION_NEXT_FRAME:uint = 0x04;

		public static const ACTION_NOT:uint = 0x12;

		public static const ACTION_OR:uint = 0x11;

		public static const ACTION_PLAY:uint = 0x06;

		public static const ACTION_POP:uint = 0x17;

		public static const ACTION_PREVIOUS_FRAME:uint = 0x05;

		public static const ACTION_PUSH:uint = 0x96;

		public static const ACTION_PUSH_DUPLICATE:uint = 0x4c;

		public static const ACTION_RANDOM_NUMBER:uint = 0x30;

		public static const ACTION_REMOVE_SPRITE:uint = 0x25;

		public static const ACTION_RETURN:uint = 0x3e;

		public static const ACTION_SET_MEMBER:uint = 0x4f;

		public static const ACTION_SET_PROPERTY:uint = 0x23;

		public static const ACTION_SET_TARGET:uint = 0x8b;

		public static const ACTION_SET_TARGET_2:uint = 0x20;

		public static const ACTION_SET_VARIABLE:uint = 0x1d;

		public static const ACTION_STACK_SWAP:uint = 0x4d;

		public static const ACTION_START_DRAG:uint = 0x27;

		public static const ACTION_STOP:uint = 0x07;

		public static const ACTION_STOP_SOUNDS:uint = 0x09;

		public static const ACTION_STORE_REGISTER:uint = 0x87;

		public static const ACTION_STRICT_EQUALS:uint = 0x66;

		public static const ACTION_STRING_ADD:uint = 0x21;

		public static const ACTION_STRING_EQUALS:uint = 0x13;

		public static const ACTION_STRING_EXTRACT:uint = 0x15;

		public static const ACTION_STRING_GREATER:uint = 0x68;

		public static const ACTION_STRING_LENGTH:uint = 0x14;

		public static const ACTION_STRING_LESS:uint = 0x29;

		public static const ACTION_SUBTRACT:uint = 0x0b;

		public static const ACTION_TARGET_PATH:uint = 0x45;

		public static const ACTION_THROW:uint = 0x2a;

		public static const ACTION_TOGGLE_QUALITY:uint = 0x08;

		public static const ACTION_TO_INTEGER:uint = 0x18;

		public static const ACTION_TO_NUMBER:uint = 0x4a;

		public static const ACTION_TO_STRING:uint = 0x4b;

		public static const ACTION_TRACE:uint = 0x26;

		public static const ACTION_TRY:uint = 0x8f;

		public static const ACTION_TYPE_OF:uint = 0x44;

		public static const ACTION_WAIT_FOR_FRAME:uint = 0x8a;

		public static const ACTION_WAIT_FOR_FRAME_2:uint = 0x8d;

		public static const ACTION_WITH:uint = 0x94;

		private static var _actionsCodeMap:Object;

		public static function getActionInfoByCode(code:uint):ActionInfo
		{
			if(_actionsCodeMap === null){
				_actionsCodeMap = initActionsCodeMap();
			}
			if (code in _actionsCodeMap)
			{
				return _actionsCodeMap[code];
			}

			return null;
		}

		private static function initActionsCodeMap():Object
		{
			var obj:Object = {};
			obj[0x04] = new ActionInfo(0x04, "ActionNextFrame", ActionNextFrame, 3);
			obj[0x05] = new ActionInfo(0x05, "ActionPreviousFrame", ActionPreviousFrame, 3);
			obj[0x06] = new ActionInfo(0x06, "ActionPlay", ActionPlay, 3);
			obj[0x07] = new ActionInfo(0x07, "ActionStop", ActionStop, 3);
			obj[0x08] = new ActionInfo(0x08, "ActionToggleQuality", ActionToggleQuality, 3);
			obj[0x09] = new ActionInfo(0x09, "ActionStopSounds", ActionStopSounds, 3);
			obj[0x0a] = new ActionInfo(0x0a, "ActionAdd", ActionAdd, 4);
			obj[0x0b] = new ActionInfo(0x0b, "ActionSubtract", ActionSubtract, 4);
			obj[0x0c] = new ActionInfo(0x0c, "ActionMultiply", ActionMultiply, 4);
			obj[0x0d] = new ActionInfo(0x0d, "ActionDivide", ActionDivide, 4);
			obj[0x0e] = new ActionInfo(0x0e, "ActionEquals", ActionEquals, 4);
			obj[0x0f] = new ActionInfo(0x0f, "ActionLess", ActionLess, 4);
			obj[0x10] = new ActionInfo(0x10, "ActionAnd", ActionAnd, 4);
			obj[0x11] = new ActionInfo(0x11, "ActionOr", ActionOr, 4);
			obj[0x12] = new ActionInfo(0x12, "ActionNot", ActionNot, 4);
			obj[0x13] = new ActionInfo(0x13, "ActionStringEquals", ActionStringEquals, 4);
			obj[0x14] = new ActionInfo(0x14, "ActionStringLength", ActionStringLength, 4);
			obj[0x15] = new ActionInfo(0x15, "ActionStringExtract", ActionStringExtract, 4);
			obj[0x17] = new ActionInfo(0x17, "ActionPop", ActionPop, 4);
			obj[0x18] = new ActionInfo(0x18, "ActionToInteger", ActionToInteger, 4);
			obj[0x1c] = new ActionInfo(0x1c, "ActionGetVariable", ActionGetVariable, 4);
			obj[0x1d] = new ActionInfo(0x1d, "ActionSetVariable", ActionSetVariable, 4);
			obj[0x20] = new ActionInfo(0x20, "ActionSetTarget2", ActionSetTarget2, 4);
			obj[0x21] = new ActionInfo(0x21, "ActionStringAdd", ActionStringAdd, 4);
			obj[0x22] = new ActionInfo(0x22, "ActionGetProperty", ActionGetProperty, 4);
			obj[0x23] = new ActionInfo(0x23, "ActionSetProperty", ActionSetProperty, 4);
			obj[0x24] = new ActionInfo(0x24, "ActionCloneSprite", ActionCloneSprite, 4);
			obj[0x25] = new ActionInfo(0x25, "ActionRemoveSprite", ActionRemoveSprite, 4);
			obj[0x26] = new ActionInfo(0x26, "ActionTrace", ActionTrace, 4);
			obj[0x27] = new ActionInfo(0x27, "ActionStartDrag", ActionStartDrag, 4);
			obj[0x28] = new ActionInfo(0x28, "ActionEndDrag", ActionEndDrag, 4);
			obj[0x29] = new ActionInfo(0x29, "ActionStringLess", ActionStringLess, 4);
			obj[0x2a] = new ActionInfo(0x2a, "ActionThrow", ActionThrow, 7);
			obj[0x2b] = new ActionInfo(0x2b, "ActionCastOp", ActionCastOp, 7);
			obj[0x2c] = new ActionInfo(0x2c, "ActionImplementsOp", ActionImplementsOp, 7);
			obj[0x30] = new ActionInfo(0x30, "ActionRandomNumber", ActionRandomNumber, 4);
			obj[0x31] = new ActionInfo(0x31, "ActionMBStringLength", ActionMBStringLength, 4);
			obj[0x32] = new ActionInfo(0x32, "ActionCharToAscii", ActionCharToAscii, 4);
			obj[0x33] = new ActionInfo(0x33, "ActionAsciiToChar", ActionAsciiToChar, 4);
			obj[0x34] = new ActionInfo(0x34, "ActionGetTime", ActionGetTime, 4);
			obj[0x35] = new ActionInfo(0x35, "ActionMBStringExtract", ActionMBStringExtract, 4);
			obj[0x36] = new ActionInfo(0x36, "ActionMBCharToAscii", ActionMBCharToAscii, 4);
			obj[0x37] = new ActionInfo(0x37, "ActionMBAsciiToChar", ActionMBAsciiToChar, 4);
			obj[0x3a] = new ActionInfo(0x3a, "ActionDelete", ActionDelete, 5);
			obj[0x3b] = new ActionInfo(0x3b, "ActionDelete2", ActionDelete2, 5);
			obj[0x3c] = new ActionInfo(0x3c, "ActionDefineLocal", ActionDefineLocal, 5);
			obj[0x3d] = new ActionInfo(0x3d, "ActionCallFunction", ActionCallFunction, 5);
			obj[0x3e] = new ActionInfo(0x3e, "ActionReturn", ActionReturn, 5);
			obj[0x3f] = new ActionInfo(0x3f, "ActionModulo", ActionModulo, 5);
			obj[0x40] = new ActionInfo(0x40, "ActionNewObject", ActionNewObject, 5);
			obj[0x41] = new ActionInfo(0x41, "ActionDefineLocal2", ActionDefineLocal2, 5);
			obj[0x42] = new ActionInfo(0x42, "ActionInitArray", ActionInitArray, 5);
			obj[0x43] = new ActionInfo(0x43, "ActionInitObject", ActionInitObject, 5);
			obj[0x44] = new ActionInfo(0x44, "ActionTypeOf", ActionTypeOf, 5);
			obj[0x45] = new ActionInfo(0x45, "ActionTargetPath", ActionTargetPath, 5);
			obj[0x46] = new ActionInfo(0x46, "ActionEnumerate", ActionEnumerate, 5);
			obj[0x47] = new ActionInfo(0x47, "ActionAdd2", ActionAdd2, 5);
			obj[0x48] = new ActionInfo(0x48, "ActionLess2", ActionLess2, 5);
			obj[0x49] = new ActionInfo(0x49, "ActionEquals2", ActionEquals2, 5);
			obj[0x4a] = new ActionInfo(0x4a, "ActionToNumber", ActionToNumber, 5);
			obj[0x4b] = new ActionInfo(0x4b, "ActionToString", ActionToString, 5);
			obj[0x4c] = new ActionInfo(0x4c, "ActionPushDuplicate", ActionPushDuplicate, 5);
			obj[0x4d] = new ActionInfo(0x4d, "ActionStackSwap", ActionStackSwap, 5);
			obj[0x4e] = new ActionInfo(0x4e, "ActionGetMember", ActionGetMember, 5);
			obj[0x4f] = new ActionInfo(0x4f, "ActionSetMember", ActionSetMember, 5);
			obj[0x50] = new ActionInfo(0x50, "ActionIncrement", ActionIncrement, 5);
			obj[0x51] = new ActionInfo(0x51, "ActionDecrement", ActionDecrement, 5);
			obj[0x52] = new ActionInfo(0x52, "ActionCallMethod", ActionCallMethod, 5);
			obj[0x53] = new ActionInfo(0x53, "ActionNewMethod", ActionNewMethod, 5);
			obj[0x55] = new ActionInfo(0x55, "ActionEnumerate2", ActionEnumerate2, 6);
			obj[0x60] = new ActionInfo(0x60, "ActionBitAnd", ActionBitAnd, 5);
			obj[0x61] = new ActionInfo(0x61, "ActionBitOr", ActionBitOr, 5);
			obj[0x62] = new ActionInfo(0x62, "ActionBitXor", ActionBitXor, 5);
			obj[0x63] = new ActionInfo(0x63, "ActionBitLShift", ActionBitLShift, 5);
			obj[0x64] = new ActionInfo(0x64, "ActionBitRShift", ActionBitRShift, 5);
			obj[0x65] = new ActionInfo(0x65, "ActionBitURShift", ActionBitURShift, 5);
			obj[0x66] = new ActionInfo(0x66, "ActionStrictEquals", ActionStrictEquals, 6);
			obj[0x67] = new ActionInfo(0x67, "ActionGreater", ActionGreater, 6);
			obj[0x68] = new ActionInfo(0x68, "ActionStringGreater", ActionStringGreater, 6);
			obj[0x69] = new ActionInfo(0x69, "ActionExtends", ActionExtends, 7);
			obj[0x81] = new ActionInfo(0x81, "ActionGotoFrame", ActionGotoFrame, 3);
			obj[0x83] = new ActionInfo(0x83, "ActionGetURL", ActionGetURL, 3);
			obj[0x87] = new ActionInfo(0x87, "ActionStoreRegister", ActionStoreRegister, 5);
			obj[0x88] = new ActionInfo(0x88, "ActionConstantPool", ActionConstantPool, 5);
			obj[0x8a] = new ActionInfo(0x8a, "ActionWaitForFrame", ActionWaitForFrame, 3);
			obj[0x8b] = new ActionInfo(0x8b, "ActionSetTarget", ActionSetTarget, 3);
			obj[0x8c] = new ActionInfo(0x8c, "ActionGoToLabel", ActionGoToLabel, 3);
			obj[0x8d] = new ActionInfo(0x8d, "ActionWaitForFrame2", ActionWaitForFrame2, 4);
			obj[0x8e] = new ActionInfo(0x8e, "ActionDefineFunction2", ActionDefineFunction2, 7);
			obj[0x8f] = new ActionInfo(0x8f, "ActionTry", ActionTry, 7);
			obj[0x94] = new ActionInfo(0x94, "ActionWith", ActionWith, 5);
			obj[0x96] = new ActionInfo(0x96, "ActionPush", ActionPush, 4);
			obj[0x99] = new ActionInfo(0x99, "ActionJump", ActionJump, 4);
			obj[0x9a] = new ActionInfo(0x9a, "ActionGetURL2", ActionGetURL2, 4);
			obj[0x9b] = new ActionInfo(0x9b, "ActionDefineFunction", ActionDefineFunction, 5);
			obj[0x9d] = new ActionInfo(0x9d, "ActionIf", ActionIf, 4);
			obj[0x9e] = new ActionInfo(0x9e, "ActionCall", ActionCall, 4);
			obj[0x9f] = new ActionInfo(0x9f, "ActionGotoFrame2", ActionGotoFrame2, 4);

			return obj;
		}

		internal var _actionClass:Class;

		internal var _code:uint;

		internal var _name:String;

		internal var _shortName:String;

		internal var _version:uint;

		public function ActionInfo(code:uint, name:String, actionClass:Class, version:uint)
		{
			_code = code;
			_name = name;
			_version = version;
			_actionClass = actionClass;

			var shortName:String;
			if (_name.indexOf("Action") === 0)
			{
				shortName = name.charAt(6).toLocaleLowerCase() + name.substring(7);
			}
			else
			{
				shortName = name;
			}
			_shortName = shortName;
		}

		public function get actionClass():Class
		{
			return _actionClass;
		}

		public function get code():uint
		{
			return _code;
		}

		public function get name():String
		{
			return _name;
		}

		public function get shortName():String
		{
			return _shortName;
		}

		public function get version():uint
		{
			return _version;
		}
	}
}
